package com.geticsen.leetcode;
//https://leetcode-cn.com/problems/task-scheduler/
public class Solution_621 {
    public int leastInterval(char[] tasks, int n) {
        int max = 0;
        int count = 0;
        int len = tasks.length;
        int[] counter = new int[26];
        for (char task : tasks) {
            max = Math.max(++counter[task - 'A'], max);
        }
        for (int i = 0; i < 26; i++) {
            if (max == counter[i]) {
                count++;
            }
        }
        return Math.max(len, (max - 1) * (n + 1) + count);
    }
}
